package com._520it.crm.web.controller;

import com._520it.crm.domain.Employee;
import com._520it.crm.domain.Pos;
import com._520it.crm.domain.Pos;
import com._520it.crm.page.AjaxResult;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.PosQueryObject;
import com._520it.crm.service.IPosService;
import com._520it.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/pos")
public class PosController {

    @Autowired
    private IPosService posService;

    @RequestMapping("")
    public String index() {
        return "pos";
    }

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(PosQueryObject qo) {
        PageResult result = posService.queryPage(qo);
        return result;
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Pos> selectListForEmployeeForm(){
        List<Pos> result = posService.selectAll();
        return result;
    }

    @RequestMapping("/save")
    @ResponseBody
    public AjaxResult save(Pos pos){
        AjaxResult result = null;
        try{
            posService.insert(pos);
            result = new AjaxResult(true,"保存成功");
        }catch(Exception e){
            e.printStackTrace();
            result = new AjaxResult("保存失败,请联系管理员!");
        }
        return result;
    }
    @RequestMapping("/update")
    @ResponseBody
    public AjaxResult update(Pos pos){
        AjaxResult result = null;
        try{
            posService.updateByPrimaryKey(pos);
            result = new AjaxResult(true,"更新成功");
        }catch(Exception e){
            e.printStackTrace();
            result = new AjaxResult("更新失败,请联系管理员!");
        }
        return result;
    }
    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult delete(Long id){
        AjaxResult result = null;
        try{
            posService.deleteByPrimaryKey(id);
            result = new AjaxResult(true,"删除成功");
        }catch(Exception e){
            e.printStackTrace();
            result = new AjaxResult("删除失败,请联系管理员!");
        }
        return result;
    }

}
